<script>
  /**
   * @param {number[]} nums
   * @return {void} Do not return anything, modify nums in-place instead.
   */
  var nums = [0, 1, 0, 3, 12];
  var moveZeroes = function (nums) {
    var len = nums.length;
    var j = 0; // j 用来记录非0的个数
    for (var i = 0; i < len; i++) {
      if (nums[i] !== 0) {
        nums[j] = nums[i];
        j++;
      }
    }
    // 从j开始到len的位置都是0
    for (var i = j; i < len; i++) {
      nums[i] = 0;
    }
    return nums;
  };
  console.log(moveZeroes(nums)); // [1,3,12,0,0]
</script>
